﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="email_write.aspx.cs" Inherits="Ccit.OA.Email.email_write" %>

<%@ Register assembly="FreeTextBox" namespace="FreeTextBoxControls" tagprefix="FTB" %>
<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<%@ Register src="../UserControls/AttachUpLoad.ascx" tagname="AttachUpLoad" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>编写新邮件</title>
   <script language="javascript" src="../script/jquery.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jbase64.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jsonlib.js" type="text/javascript" ></script>
    <script language="javascript" src="../script/StringClass_Ext.js" type="text/javascript" ></script>
    
    <script language="javascript" src="../script/jwindow.js" type="text/javascript"></script> 

    <script type="text/javascript">
    
    function CheckVal()
    {
        var bFlag = true ;
        if(Number(document.getElementById("hidspace").value) < 0)
        {
            if(confirm("您的邮件空间已使用完毕,是否继续发送?"))
            {
            }   
            else{
               return false;
            }
        }
        if(document.getElementById("txtZT").value =="")
        {
            alert("邮件标题不允许为空!");
            bFlag = false ;
        }
        if(document.getElementById("hidNBSJRId").value =="")
        {
            alert("内部收件人不允许为空!");
            bFlag = false ;
        }
            return bFlag ;
    }
    
        //发送邮件
        function AddEmail()
        {
            if(CheckVal())
            {
                var jsonStr = jsonObj("0");  //非草稿
                var attachXML = GetAttachesXML("2");
                var yjbz = $get("hidYJBZ").value;
                //var wbyjbz = document.getElementById("ddWBYX").options[document.getElementById("ddWBYX").selectedIndex].value; 
                var wbyjbz = document.getElementById("ddWBYX").value;
                PageMethods.AddEmails(jsonStr,attachXML,yjbz,wbyjbz,AddCallBack) ;
                return true;
            }
            return false;
        }
        
        //保存到草稿箱
        function SaveEmails()
        {
            if(CheckVal())
            {
                var jsonStr = jsonObj("1"); //草稿
                var attachXML = GetAttachesXML("2");
                var yjbz = $get("hidYJBZ").value;
                PageMethods.SaveEmails(jsonStr,attachXML,yjbz,SaveCallBack);
                return true;
            }
            return false;
        }
    
        function jsonObj(saveType) //返回序列化后的字符串
        {
            var strvalue = "0";
            var MsDetails ={};
                MsDetails.emlId = $get("hidEMLID").value;
                MsDetails.emlTitle = $get("txtZT").value;
                MsDetails.emlContent = $get("TemplateContext").value;
                if(document.getElementById("TXBZ").checked == true)
                {
                    strvalue = "1";
                }
                MsDetails.readlogo = strvalue;
                MsDetails.emllevel = document.getElementById("ddWBYX").value;//document.getElementById("ddlYXJB").options[document.getElementById("ddlYXJB").selectedIndex].value; 
                MsDetails.draftlogo = saveType;         //草稿还是非草稿  1 草稿，0 非草稿
                MsDetails.type = "0";                   //邮件类型
                MsDetails.emlLength = document.getElementById("TemplateContext").value.length;   //邮件大小
                MsDetails.jjuserId = $get("hidYGXH").value; 
                MsDetails.sendtime = "";      //获取日期与时间
                MsDetails.jjusername = "";    
                MsDetails.jjaddress = "";       //寄件人地址  当有外部邮件时候，该字段有效
                MsDetails.nbsjlogo = $get("hidNBSJRType").value;
                MsDetails.nbsjRange = $get("hidNBSJRId").value;
                //alert(MsDetails.nbsjRange + ","+MsDetails.nbsjlogo);
                //return false;
                MsDetails.nbcslogo = $get("hidNBCSRType").value;
                MsDetails.nbcsRange = $get("hidNBCSRId").value;
                MsDetails.nbmjlogo = $get("hidNBMSRType").value;
                MsDetails.nbmjRange = $get("hidNBMSRId").value;
                MsDetails.wbsjlist = $get("txtWBSJR").value;
                MsDetails.wbcslist = $get("txtWBCSR").value;
                MsDetails.wbmslist = $get("txtWBMSR").value;
                MsDetails.wbOnlyId = "";
                MsDetails.fjcount = "";
                MsDetails.yjysxx = "";
                MsDetails.cjdatetime = $get("hidTime").value;
                if(document.getElementById("SAVEFLAG").checked == true)
                {
                    strvalue = "1";
                }
                MsDetails.saveflag = strvalue;
                MsDetails.agencId = $get("hidJG").value;
                MsDetails.deptId = $get("hidYGBM").value;
                MsDetails.jobId = $get("hidYGZW").value;
                MsDetails.levelId = $get("hidYGJB").value;
                MsDetails.cjuserId = $get("hidYGXH").value;
                MsDetails.decoder = "";      //内容解码标志，针对外部邮件有效
                var jsonStr = JSON.stringify(MsDetails,function(key,value){return value;});  
                return jsonStr;
        }
   
        function AddCallBack(sResult)
        {
            eval("var resultObj=" + sResult);
            var resultSign = resultObj.resultSign;

            if(resultSign == "1")
            {
                alert("邮件发送成功!");
                //var sParam = "TITLE=收件箱&YJBZ=0";
	             //var encodeParam = base64encode(sParam);
                window.location.href="email_wdyj_index.aspx";
            }
            else {
             alert("邮件发送失败!"); 
            }
        }
    
        function SaveCallBack(sResult)
        {
             eval("var resultObj=" + sResult);
             var resultSign = resultObj.draftlogo;
             
             if(resultSign == "3")
             {
                alert("草稿保存失败!");
             }
             else if(resultSign == "1")
             {
                alert("保存成功!");
             }
        }
   
        //更多收件人 
        function moreEmail()
        {
            if(document.getElementById("trInnerCopy").style.display == "none")
            {
                document.getElementById("trInnerCopy").style.display = "block";
            }
            else{
                document.getElementById("trInnerCopy").style.display = "none";
            }
            
            if(document.getElementById("trInnerSecret").style.display == "none")
            {
                document.getElementById("trInnerSecret").style.display = "block";
            }
            else{
                document.getElementById("trInnerSecret").style.display = "none";
            }
            //判断是否开通外部邮件
            if(document.getElementById("hidEndOutShow").value != "0")
            {
                if(document.getElementById("trOuter").style.display == "none")
                {
                    document.getElementById("trOuter").style.display = "block";
                }
                else{
                    document.getElementById("trOuter").style.display = "none";
                }
                
                if(document.getElementById("OuterCopy").style.display == "none")
                {
                    document.getElementById("OuterCopy").style.display = "block";
                }
                else{
                    document.getElementById("OuterCopy").style.display = "none";
                }
                if(document.getElementById("OuterSecret").style.display == "none")
                {
                    document.getElementById("OuterSecret").style.display = "block";
                }
                else{
                    document.getElementById("OuterSecret").style.display = "none";
                }
            }
            
            return false;
        }


        function doSetRange(vCtrlType,vCtrlId,vCtrlName) {
            OpenRangeSelect(vCtrlType,vCtrlId,vCtrlName,"0");
        } 
           
		function popUp() {
        newX = document.getElementById("img4").getBoundingClientRect().left + document.body.scrollLeft;
        newY = document.getElementById("img4").getBoundingClientRect().top + document.body.scrollTop;
        menu = document.getElementById("root");
          if ( menu.style.display == ""){
            menu.style.display = "none" }
          else {
             menu.style.display = ""}

            menu.style.pixelLeft = newX;
            menu.style.pixelTop = newY + 20;
        }
        
        function popOver()
        {
            document.getElementById("root").style.display = "none";
        }
        
        function doWebRange(vCtrlId,vCtrlName,separator) {	
	        var UrlParam = "selType=1&" + "&ctrlid=" + vCtrlId + "&ctrlname=" + vCtrlName;
	        UrlParam += "&sep=" + separator;
	        var encodeParam = base64encode(UrlParam);
		    var strURL = "../email/email_wbyj_tree.aspx?" + encodeParam;
		    OpenWindow(strURL,"",300,350);
        } 


    </script>
	
	<style type="text/css">
        a.           { font: 9pt "宋体"; cursor: hand; font-size: 9pt ; color: #ffffff; text-decoration: none }
        a:active     { font: 9pt "宋体"; cursor: hand; color: #FF0033 }
        a.cc:hover   { font: 9pt "宋体"; cursor: hand; color: #FF0033}
        .box         { font: 9pt "宋体"; position: absolute;  background: #eee }
    </style>
	
</head>
	<body MS_POSITIONING="GridLayout" onclick="popOver()">
		<ccit:ActionForm id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"  EnablePageMethods="true"/>
			<input id="Val" type="hidden" value="0" runat="server" NAME="Val"> <input id="hidYJXH" type="hidden" runat="server" NAME="hidYJXH">
			<input id="hidYJBZ" type="hidden" runat="server" NAME="hidYJBZ">
			<table class="tbToolbar" cellSpacing="0" cellPadding="0" width="98%" align="center" border="0">
				<tr>
					<td align="left">
						<div class="tbSeparator"></div>
					</td>
					<td class="titlebar"><nobr><IMG src="../images/public/pageicon.gif" border="0">
							我的邮件 -&gt; 撰写邮件</nobr>
					</td>
					<td align="right"><nobr>
					        <asp:LinkButton ID="lntSend" runat="server" CssClass="linktext">							
							<IMG src="../images/toolbar/turn.GIF" border="0" runat="server" id="img1">发送邮件</asp:LinkButton>
    				        <asp:LinkButton ID="lntSave" runat="server" CssClass="linktext">							
							<IMG src="../images/toolbar/rename_bq.gif" border="0" runat="server" id="img2">保存邮件</asp:LinkButton>			
							<a href="javascript:OpenUpLoadPage();" Class="linktext"><IMG src="../images/toolbar/save.gif" border="0" runat="server" id="img3">插入附件</a>
					       <a href="javascript:" onmouseover="popUp();" onclick="popOver();" Class="linktext" tooltip="点击向邮件插入签名信息">							
							<IMG src="../images/toolbar/worklog.gif" border="0" runat="server" id="img4">插入签名</a>						
							<asp:LinkButton CssClass="linktext" Runat="server" ID="lnbList" tooltip="点击显示邮件内部抄送人,内部密送人">			
							<IMG src="../images/toolbar/arrdowna.gif" border="0" runat="server" id="imgDown">更多收件人
							</asp:LinkButton>
						</nobr>
					</td>
					<td align="left">
						<div class="tbSeparatorEnd"></div>
					</td>
				</tr>
			</table>
			<table class="tableborder" cellSpacing="0" cellPadding="0" width="98%" align="center">
				<TBODY>
					<tbody id="NOTE_EDIT">
						<TR runat=server id="trInner">
							<TD class="pformleft" align="right" width="80"><nobr><b><a Class="linktext" href="javascript:doSetRange('hidNBSJRType','hidNBSJRId','txtNBSJR');">内部收件人</a></b></nobr></TD>
							<TD class="pformright" align="left" colSpan="3" title="请点击旁边的链接选择人员"><asp:textbox id="txtNBSJR" CssClass="inputreadonly" Runat="server" Width="98%" readonly="True"></asp:textbox>
							<input id="hidNBSJRId" type="hidden" runat="server" NAME="hidNBSJRId"><input id="hidNBSJRType" type="hidden" runat="server" NAME="hidNBSJRType">
							</TD>
						</TR>
						<TR runat="server" id="trInnerCopy" style="display:none">
							<TD class="pformleft" align="right" width="80"><nobr><b><a Class="linktext" href="javascript:doSetRange('hidNBCSRType','hidNBCSRId','txtNBCSR');">内部抄送人</a></b></nobr></TD>
							<TD class="pformright" align="left" colSpan="3" title="请点击旁边的链接选择人员"><asp:textbox id="txtNBCSR" CssClass="inputreadonly" Runat="server" Width="98%" readonly="True"></asp:textbox>
							<input id="hidNBCSRId" type="hidden" name="hidNBCSRId" runat="server"><input id="hidNBCSRType" type="hidden" name="hidNBCSRType" runat="server">
							</TD>
						</TR>
						<TR runat="server" id="trInnerSecret" style="display:none">
							<TD class="pformleft" align="right" width="80"><nobr><b><a Class="linktext" href="javascript:doSetRange('hidNBMSRType','hidNBMSRId','txtNBMSR');">内部密送人</a></b></nobr></TD>
							<TD class="pformright" align="left" colSpan="3" title="请点击旁边的链接选择人员"><asp:textbox id="txtNBMSR" CssClass="inputreadonly" Runat="server" Width="98%" readonly="True"></asp:textbox>
							<input id="hidNBMSRId" type="hidden" name="hidNBMSRId" runat="server"><input id="hidNBMSRType" type="hidden" name="hidNBMSRType" runat="server">
							</TD>
						</TR>
						<div style="display:none">
						<TR runat=server id="trOuter" style="display:none">
							<TD class="pformleft" align="right" width="80" title="多个邮件地址之间请用分号分隔"><nobr><b>外部收件人</b></nobr></TD>
							<TD class="pformright" align="left" colSpan="3" title="多个邮件地址之间请用分号分隔"><asp:textbox id="txtWBSJR" CssClass="input" Runat="server" Width="98%"></asp:textbox>
							<input type="hidden" runat="server" id="hidWBSJEmlId" NAME="hidWBSJEmlId"><input  type="hidden" runat="server" id="hidSJEml" NAME="hidSJEml">
							</TD>
						</TR>
						
						<TR runat="server" id="OuterCopy" style="display:none">
							<TD class="pformleft" align="right" width="80" title="多个邮件地址之间请用分号分隔"><nobr><b>外部抄送人</b></nobr></TD>
							<TD class="pformright" align="left" colSpan="3" title="多个邮件地址之间请用分号分隔"><asp:textbox id="txtWBCSR" CssClass="input" Runat="server" Width="98%"></asp:textbox></TD>
						</TR>
						<TR runat="server" id="OuterSecret" style="display:none">
							<TD class="pformleft" align="right" width="80" title="多个邮件地址之间请用分号分隔"><nobr><b>外部密送人</b></nobr></TD>
							<TD class="pformright" align="left" colSpan="3" title="多个邮件地址之间请用分号分隔"><asp:textbox id="txtWBMSR" CssClass="input" Runat="server" Width="98%"></asp:textbox></TD>
						</TR>
						</div>
						<TR>
							<TD class="pformleft" align="right" width="80"><nobr><b>主题</b></nobr></TD>
							<TD class="pformright" align="left" colSpan="3"><asp:textbox id="txtZT" 
                                    CssClass="input" Runat="server" Width="98%"></asp:textbox></TD>
						</TR>
						<tr>
							<td class="pformstrip" align="right">相关附件</td>
							<td class="pformstrip" align="left" id="MyFileList" width="100%" colSpan="3" runat="server">
							    <uc1:AttachUpLoad  ID="AttUpLoad" ShowStyle="1" runat="server" />
							</td>
						</tr>
						<TR>
							<TD class="pformleft" vAlign="top" align="right"><nobr><b>内容</b></nobr></TD>
							<td class="pformright" colSpan="3">
								<FTB:FREETEXTBOX id="TemplateContext"  runat="server" Width="100%" height="350" tabIndex="2" FontFacesMenuPath="../css/">
								</FTB:FREETEXTBOX>
                            </td>
						</TR>						
						<TR>
						    <td></td>
							<td class="pformright" colSpan="3">&nbsp;优先级别：<asp:dropdownlist id="ddlYXJB" CssClass="inputselect" Runat="server" Width="60">
									<asp:ListItem Value="1">高</asp:ListItem>
									<asp:ListItem Value="3" Selected>普通</asp:ListItem>
									<asp:ListItem Value="5">低</asp:ListItem>
								</asp:dropdownlist>
								<asp:checkbox id="SAVEFLAG" Runat="server" Text="发信后保存到已发送邮件夹" Checked="True"></asp:checkbox>&nbsp;&nbsp;
								<asp:checkbox id="TXBZ" Runat="server" Text="对方读到信时给我回应"></asp:checkbox>&nbsp;<font color=red>(只对内部邮件有效)</font>&nbsp; 
	
							</td>
						</TR>
						<tr id="tr3" runat="server" style="display:none">
						<td></td>
						    <td  class="pformright" colSpan="3">
						        &nbsp;发送外部邮件使用邮箱账号：<asp:DropDownList ID="ddWBYX" CssClass="inputselect" runat="server" Width="200px"></asp:DropDownList>
						    </td>
						</tr>
					</tbody>
					<tr>
						<td class="pformstrip" align="center" width="100%" colSpan="4">
						<input type="button" id="btnOK" class="button" value="发送"  onclick="return AddEmail()" />&nbsp;&nbsp;
						<input type="button" id="btnOKBack" class="button" value="保存到草稿夹" onclick="SaveEmails();" />&nbsp;&nbsp;
						<input class="button" id="btnClose" onclick="javascript:window.close();" type="button" value="关闭" runat="server"> 
						<input onclick="javascript:history.go(-1);" class="button" id="btnBack" type="button" value="返回" runat="server">
						</td>
					</tr>
			</table>
			<input type="hidden"  id="hidvar" />
					<input type="hidden" id="hidYGXH" runat="server">
					<input type="hidden" id="hidYGJB" runat="server" />
					<input type="hidden" id="hidYGBM" runat="server" />
					<input type="hidden" id="hidYGZW" runat="server" />
					<input type="hidden" id="hidJG" runat="server" />
					<input type="hidden" id="hidEMLID" runat="server" />
					<input type="hidden" id="hidTime" runat="server" />
					<input type="hidden" id="hidspace" runat="server" />
					<input type="hidden" id="hidEndOutShow" runat="server" />
					<div id="root" class="box" style="display : none">
					<table id="menuTable" style="border:#999999 solid;border-width:1 1 1 1" cellSpacing="0" cellPadding="0"   runat="server">
					</table>
                    </div>
           
		</ccit:ActionForm>
	</body>
</html>
<script language=javascript>
        
        if(document.getElementById("hidEndOutShow").value == "0")
        {
            document.getElementById("tr3").style.display = "none";    
        }   
        else{
            document.getElementById("tr3").style.display = "block";    
        }
        
       function signClick(strValue)
       {
            var sContent = "<br>" + strValue; 
                 if (TemplateContext_HtmlMode) 
                    {
		                TemplateContext_editor.document.body.innerText +=sContent ;
		                $get("TemplateContext").value = TemplateContext_editor.document.body.innerText ;
	                } 
	                else 
	                {
		                TemplateContext_editor.document.body.innerHTML += sContent;  
		                $get("TemplateContext").value =TemplateContext_editor.document.body.innerHTML ;
	                }
	                if ($get("TemplateContext").value == '<P>&nbsp;</P>') {
		                $get("TemplateContext").value = '';
	                }
	                
	              document.getElementById("root").style.display = "none";  
	                
	                
       }           
       // 注册事件
</script>